package com.bdwm.util;

import java.io.UnsupportedEncodingException;

import com.bdwm.model.BorrowDtl;
import com.bdwm.model.Device;
import com.bdwm.model.User;

public class ParseRequestPara {
	public static String parseRequestParameter(String args) throws UnsupportedEncodingException {
		return new String(args.getBytes("ISO-8859-1"),"utf-8");
	}
	public static String checkDeviceParameter(Device device) {
		String info = "success";
		if(isNull(device.getDeviceName())) {
			return "deviceName are not allowed to be empty";
		}
		
		if(isNull(device.getDeviceAssetNum())) {
			return "deviceAssetNum are not allowed to be empty";
		}
		
		if(isNull(device.getOsType())) {
			return "osType are not allowed to be empty";
		}
		
		if(isNull(device.getVersionType())) {
			return "versionType are not allowed to be empty";
		}
		
		if(isNull(device.getDeviceResolution())) {
			return "deviceResolution are not allowed to be empty";
		}
		
		if(isNull(device.getRemark())) {
			return "remark are not allowed to be empty";
		}
		
		if(isNull(device.getDeviceDept())) {
			return "deviceDept are not allowed to be empty";
		}
		
		if(isNull(device.getDeviceBelongs())) {
			return "deviceBelongs are not allowed to be empty";
		}
		return info;
	}
	
	public static String checkUserParameter(User user) {
		String info = "success";
		
		if(isNull(user.getUserName())) {
			return "userName are not allowed to be empty";
		}
		
		if(isNull(user.getUserEmail())) {
			return "userEmail are not allowed to be empty";
		}
		
		if(isNull(user.getUserDept())) {
			return "userDept are not allowed to be empty";
		}
		
		if(isNull(user.getUserTel())) {
			return "userTel are not allowed to be empty";
		}
		
		if(isNull(user.getPassword())) {
			return "password are not allowed to be empty";
		}
		return info;
	}
	
	public static String checkBorrowParameter(BorrowDtl borrowdtl){
		String info = "success";
		
		if(isNull(borrowdtl.getDeviceName())){
			return "DeviceName are not allowed to be empty";
		}
		
		if(isNull(borrowdtl.getUserName())){
			return "BorrowName are not allowed to be empty";
		}
		
//		if(isNull(borrowdtl.getOsType())){
//			return "OsType are not allowed to be empty";
//		}
//		
//		if(isNull(borrowdtl.getVersionType())){
//			return "VersionType are not allowed to be empty";
//		}
		
		if(null == borrowdtl.getBorrowTime()){
			return "BorrowTime are not allowed to be empty";
		}
		
//		if(isNull(borrowdtl.getDeviceResolution())){
//			return "DeviceResolution are not allowed to be empty";
//		}
//		
//		if(isNull(borrowdtl.getDeviceDept())){
//			return "DeviceDept are not allowed to be empty";
//		}
//		
//		if(isNull(borrowdtl.getVersionType())){
//			return "VersionType DeviceResolution are not allowed to be empty";
//		}
		
		return info;
	}
	
	public static boolean isNull(String str) {
		return null == str || "".equals(str) || str.length() == 0;
	}
}
